/******************************************************************************
 *
 * Copyright:
 *    (C) 2000 - 2005 Embedded Artists AB
 *
 *****************************************************************************/


#include "../pre_emptive_os/api/osapi.h"
#include "../pre_emptive_os/api/general.h"
#include <printf_P.h>
#include <lpc2xxx.h>
#include <consol.h>
#include "../startup/config.h"
#include "testAdc.h"

/******************************************************************************
 * Defines and typedefs
 *****************************************************************************/


/*****************************************************************************
 *
 * Description:
 *    Start a conversion of one selected analogue input and return
 *    10-bit result.
 *
 * Params:
 *    [in] channel - analogue input channel to convert.
 *
 * Return:
 *    10-bit conversion result
 *
 ****************************************************************************/
tU16 getAnalogueInput(tU8 channel)
{
	//start conversion now (for selected channel)
	ADCR = (ADCR & 0xFFFFFF00) | (1 << channel) | (1 << 24);
	
	//wait til done
	while((ADDR & 0x80000000) == 0)
	  ;

	//get result and adjust to 10-bit integer
	return (ADDR>>6) & 0x3FF;
}
tU16
getAnalogueInput1(tU8 channel)
{
//  volatile tU32 cpsrReg;
  tU16 returnResult;

	AD1CR = (AD1CR & 0xFFFFFF00) | (1 << channel) | (1 << 24);

	//wait til done
	while((AD1DR & 0x80000000) == 0)
	  ;
	//get result and adjust to 10-bit integer
	returnResult = (AD1DR>>6) & 0x3FF;
  return returnResult;
}
